<?php

namespace App\Http\Controllers\H5;

use App\Library\Cms\PostItemTrait;
use App\Models\PostCatlog;
use App\Models\PostItem;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class PostController extends BaseController
{
    use PostItemTrait;

    public function index()
    {

        $catlogs = PostCatlog::available()->where('fid', 0)->orderBy('catid')->get();
        return $this->view('h5.post.index', compact('catlogs'));
    }

    public function detail($aid){
        $this->assign(['aid'=>$aid]);

        $article = PostItem::find($aid);
        if ($article)
        {
            $article->increment('views');
            $content = $article->content;
            return $this->view('h5.post.detail', compact('article', 'content'));
        } else {
            return ajaxError(404, 'article not found');
        }
    }

}
